/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package easyanimation.panel;

import easyanimation.frame.CConfig;
import easyanimation.frame.Constant;
import easyanimation.frame.Language;
import easyanimation.frame.MainWindow;
import easyanimation.panel.left.CTabLeft;
import java.awt.GridLayout;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.TitledBorder;

/**
 *
 * @author Ngoc Tan
 */
public class CLeftPanel extends JTabbedPane
{
    //Palette
    private CTabLeft m_tabPalette;
    //Module
    private CTabLeft m_tabModule;
    //Frame
    private CTabLeft m_tabFrame;
    private CTabLeft m_subTableModuleFrame;
    //Animation
    private CTabLeft m_tabAnimation;
    private CTabLeft m_subTableFrameAnimation;
    //tab index
    private int m_tabIndexCurrentI, m_tabIndexPreviousI;

    public CLeftPanel()
    {
        //------------SET BASE ATTRIBUTES
        setSize(Constant.WINDOW_WIDTH_LEFT, Constant.WINDOW_HEIGHT - Constant.WINDOW_HEIGHT_HEADER);
        setBorder(Constant.OBJ_BORDER_COMMON);
        setTabLayoutPolicy(SCROLL_TAB_LAYOUT);

        //------------ADD TAB PALETTE
        m_tabPalette = new CTabLeft(Constant.COLUMN_NAMES[Constant.TAB_INDEX_PALETTE],
                Constant.COLUMN_TAB_PALETTE_NON_EDITABLE,
                Constant.COLUMN_TAB_PALETTE_INTEGER,
                Constant.COLUMN_TAB_PALETTE_INTEGER_POSITIVE,
                true, false, false, Constant.DATA_PALETTE);
        m_tabPalette.setColumnWidth(Constant.COLUMN_TAB_PALETTE_INDEX, Constant.COLUMN_WIDTH);
        m_tabPalette.setColumnWidth(Constant.COLUMN_TAB_PALETTE_NAME, Constant.WINDOW_WIDTH_LEFT - (Constant.COLUMN_WIDTH >> 1));
        addTab(Language.PALETTE[CConfig.LANGUAGE], null, null);
        setComponentAt(Constant.TAB_INDEX_PALETTE, m_tabPalette);

        //------------ADD TAB MODULE
        m_tabModule = new CTabLeft(Constant.COLUMN_NAMES[Constant.TAB_INDEX_MODULE],
                Constant.COLUMN_TAB_MODULE_NON_EDITABLE,
                Constant.COLUMN_TAB_MODULE_INTEGER,
                Constant.COLUMN_TAB_MODULE_INTEGER_POSITIVE,
                false, true, false, Constant.DATA_MODULE);
        addTab(Language.MODULE[CConfig.LANGUAGE], null, null);
        setComponentAt(Constant.TAB_INDEX_MODULE, m_tabModule);

        //------------ADD TAB FRAME
        JPanel objFramePanel = new JPanel(new GridLayout(2, 1));
        m_tabFrame = new CTabLeft(Constant.COLUMN_NAMES[Constant.TAB_INDEX_FRAME],
                Constant.COLUMN_TAB_FRAME_NON_EDITABLE,
                Constant.COLUMN_TAB_FRAME_INTEGER,
                Constant.COLUMN_TAB_FRAME_INTEGER_POSITIVE,
                false, false, false, Constant.DATA_FRAME);
        m_tabFrame.setColumnWidth(Constant.COLUMN_TAB_FRAME_NAME, 3 * Constant.COLUMN_WIDTH);
        objFramePanel.add(m_tabFrame);

        m_subTableModuleFrame = new CTabLeft(Constant.COLUMN_NAMES[Constant.SUB_TABLE_MODULE],
                Constant.COLUMN_SUB_TABLE_NON_EDITABLE,
                Constant.COLUMN_SUB_TABLE_INTEGER,
                Constant.COLUMN_SUB_TABLE_INTEGER_POSITIVE,
                false, false, true, Constant.DATA_SUB_TABLE);
        m_subTableModuleFrame.setBorder(new TitledBorder(Language.ITS_MODULE[CConfig.LANGUAGE]));
        objFramePanel.add(m_subTableModuleFrame);
        addTab(Language.FRAME[CConfig.LANGUAGE], null, null);
        setComponentAt(Constant.TAB_INDEX_FRAME, objFramePanel);

        //------------ADD TAB ANIMATION
        JPanel objAnimationPanel = new JPanel(new GridLayout(2, 1));
        m_tabAnimation = new CTabLeft(Constant.COLUMN_NAMES[Constant.TAB_INDEX_ANIMATION],
                Constant.COLUMN_TAB_ANIMATION_NON_EDITABLE,
                Constant.COLUMN_TAB_ANIMATION_INTEGER,
                Constant.COLUMN_TAB_ANIMATION_INTEGER_POSITIVE,
                false, false, false, Constant.DATA_ANIMATION);
        m_tabAnimation.setColumnWidth(Constant.COLUMN_TAB_ANIMATION_NAME, 3 * Constant.COLUMN_WIDTH);
        objAnimationPanel.add(m_tabAnimation);

        m_subTableFrameAnimation = new CTabLeft(Constant.COLUMN_NAMES[Constant.SUB_TABLE_FRAME],
                Constant.COLUMN_SUB_TABLE_NON_EDITABLE,
                Constant.COLUMN_SUB_TABLE_INTEGER,
                Constant.COLUMN_SUB_TABLE_INTEGER_POSITIVE,
                false, false, true, Constant.DATA_SUB_TABLE);
        m_subTableFrameAnimation.setBorder(new TitledBorder(Language.ITS_FRAME[CConfig.LANGUAGE]));
        objAnimationPanel.add(m_subTableFrameAnimation);
        addTab(Language.ANIMATION[CConfig.LANGUAGE], null, null);
        setComponentAt(Constant.TAB_INDEX_ANIMATION, objAnimationPanel);
        m_tabIndexCurrentI = m_tabIndexPreviousI = 0;
    }

    @Override
    public void doLayout()
    {
        super.doLayout();
        m_tabIndexCurrentI = getSelectedIndex();
        if (m_tabIndexCurrentI != m_tabIndexPreviousI)
        {
            m_tabIndexPreviousI = m_tabIndexCurrentI;
            MainWindow.getInstance().getCenterPanel().setZoomForCenter(Constant.ZOOM_NORMAL);
            MainWindow.getInstance().getStatusPanel().setZoomForStatus(Constant.ZOOM_NORMAL);
            MainWindow.getInstance().getCenterPanel().resetRectInfos();

        }
        if (m_tabIndexCurrentI == Constant.TAB_INDEX_FRAME)
        {
            getRightPanel().setBorderTitle(Language.MODULE[CConfig.LANGUAGE]);
            if (m_tabFrame.getTable().getRowCount() < 1 || m_tabModule.getTable().getRowCount() < 1)
            {
                m_subTableModuleFrame.setShowButtons(false);
            }
            else
            {
                m_subTableModuleFrame.setShowButtons(true);
            }
        }
        else if (m_tabIndexCurrentI == Constant.TAB_INDEX_ANIMATION)
        {
            getRightPanel().setBorderTitle(Language.FRAME[CConfig.LANGUAGE]);
            if (m_tabAnimation.getTable().getRowCount() < 1 || m_tabFrame.getTable().getRowCount() < 1)
            {
                m_subTableFrameAnimation.setShowButtons(false);
            }
            else
            {
                m_subTableFrameAnimation.setShowButtons(true);
            }
        }
        else
        {
            getRightPanel().setBorderTitle("");
        }
    }

    /**
     * @return the m_tabPalette
     */
    public CTabLeft getTabPalette()
    {
        return m_tabPalette;
    }

    /**
     * @return the m_tabModule
     */
    public CTabLeft getTabModule()
    {
        return m_tabModule;
    }

    /**
     * @return the m_tabFrame
     */
    public CTabLeft getTabFrame()
    {
        return m_tabFrame;
    }

    /**
     * @return the m_tabAnimation
     */
    public CTabLeft getTabAnimation()
    {
        return m_tabAnimation;
    }

    public CRightPanel getRightPanel()
    {
        return MainWindow.getInstance().getRightPanel();
    }

    /**
     * @return the m_objSubTableModuleFrame
     */
    public CTabLeft getSubTableModuleFrame()
    {
        return m_subTableModuleFrame;
    }

    /**
     * @return the m_objSubTableFrameAnimation
     */
    public CTabLeft getSubTableFrameAnimation()
    {
        return m_subTableFrameAnimation;
    }
}

